#include <iostream>
#include <string>
#include <queue>
using namespace std;

int main()
{
	queue<int> q;
	int n, m; cin >> n >> m;
	for (int i = 1; i <= n; i++) q.push(i);
	while (q.size() > 1) {
		for(int i = 1; i < m; i++) {
			int tmp = q.front(); q.pop(); q.push(tmp);
		}
		q.pop();
	}
	cout << q.front();
	return 0;
}